package cn.tedu.fengyuback.personal.controller;

import cn.tedu.fengyuback.base.response.JsonResult;
import cn.tedu.fengyuback.personal.pojo.dto.ArticlesPram;
import cn.tedu.fengyuback.personal.pojo.dto.ArticlesQuery;
import cn.tedu.fengyuback.personal.pojo.dto.FavoritesQuery;
import cn.tedu.fengyuback.personal.pojo.dto.LikesQuery;
import cn.tedu.fengyuback.personal.pojo.vo.ArticlesVO;
import cn.tedu.fengyuback.personal.pojo.vo.UserFollowsVO;
import cn.tedu.fengyuback.personal.pojo.vo.UserVO;
import cn.tedu.fengyuback.personal.service.PersonalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/v1/personal/")
public class PersonalController {
    @Autowired
    PersonalService personalService;

    /**
     * 查询用户关注列表
     * @param id
     * @return
     */
    @GetMapping("selectUserFollows")
    public JsonResult selectUserFollows(Long id){
        log.debug("查询用户的关注列表：id={}",id);
        List<UserFollowsVO> list = personalService.selectUserFollows(id);
        log.debug("查询用户的关注列表：list={}",list);
        return JsonResult.ok(list);
    }
    /**
     * 查询用户未关注列表
     * @param id
     * @return
     */
    @GetMapping("selectUserUnFollows")
    public JsonResult selectUserUnFollows(Long id){
        log.debug("查询用户的未关注列表：id={}",id);
        List<UserVO> list = personalService.selectUserUnFollows(id);
        return JsonResult.ok(list);
    }

    /**
     * 取消关注的用户
     * @param followsUserId
     * @return
     */
    @PostMapping("unfollows/{followsUserId}")
    public JsonResult deleteByFollowsUserId(@PathVariable Long followsUserId){
        log.debug("被取消关注的用户id：id={}",followsUserId);
        personalService.deleteByFollowsUserId(followsUserId);
        return JsonResult.ok();
    }
    /**
     * 加关注
     * @param
     * @return
     */
    @PostMapping("addFollows/{id}/{data}")
    public JsonResult addFollows(@PathVariable Long id,@PathVariable Long data){
        log.debug("被关注用户的id={}",id);
        log.debug("用户的id={}",data);
        personalService.addFollows(id,data);
        return JsonResult.ok();
    }
    /**
     * 发文章
     * @param
     * @return
     */
    @PostMapping("article/release")
    public JsonResult releaseArticle(ArticlesPram articlesPram){
        log.debug("发布文章的参数={}",articlesPram);
        personalService.releaseArticle(articlesPram);
        return JsonResult.ok();
    }
    /**
     * 查询用户发布的文章
     * @param userId
     * @return
     */
    @GetMapping("article/loadArticle")
    public JsonResult selectByIdArticle(Long uId,Long userId,Long questionId,String status,Long category,Long subcategory,
                                        Long locCategory){
        List<ArticlesVO> list = personalService.selectByIdArticle(uId,userId,questionId,status,category,subcategory,locCategory);
        log.debug("用户id={}查询用户userId={}发布的文章={}",uId,userId,list);
        log.debug("大标签category={}小标签subcategory={}地区标签={}",category,subcategory,locCategory);
        return JsonResult.ok(list);
    }

    @GetMapping("article/loadArticle1")
    public JsonResult selectByIdArticle1(ArticlesQuery articlesQuery){
        log.debug("查询用户发布文章的参数={}",articlesQuery);
        List<ArticlesVO> list = personalService.selectByIdArticle1(articlesQuery);
        return JsonResult.ok(list);
    }

    /**
     * 点赞/取消点赞文章
     * @param likesQuery
     * @return
     */
    @PostMapping("article/likesStatus")
    public JsonResult changeLikesStatus(LikesQuery likesQuery){
        log.debug("更改文章点赞状态的参数={}",likesQuery);
        personalService.changeLikesStatus(likesQuery);
        return JsonResult.ok();
    }

    /**
     * 收藏/取消收藏文章
     * @param favoritesQuery
     * @return
     */
    @PostMapping("article/favoriteStatus")
    public JsonResult changeFavoriteStatus(FavoritesQuery favoritesQuery){
        log.debug("更改文章收藏状态的参数={}",favoritesQuery);
        personalService.changeFavoritesStatus(favoritesQuery);
        return JsonResult.ok();
    }
}
